Fix Comparer.sel() with date string when some comparers have no temporal overlap#669
Draft
Copilot wants to merge 2 commits into
Draft
Fix Comparer.sel() with date string when some comparers have no temporal overlap#669Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
When calling Comparer.sel(time='2022-01-03') (non-slice string): - If no data exists for that date, xarray raises KeyError → now returns empty comparer - If exact daily timestamp exists, xarray returns 0D dataset causing 'IndexVariable must be 1-dimensional' → now expanded back to 1D with expand_dims Also replaces the TODO: FAILS commented-out test with two correct failing tests that now pass after the fix.
Copilot
AI
changed the title
[WIP] Fix time arg errors in ComparerCollection.sel() method
Fix Comparer.sel() with date string when some comparers have no temporal overlap
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ComparerCollection.sel(time='2022-01-03')raised an error instead of silently dropping comparers with no data on that date.Two bugs in
Comparer.sel()whentimeis a non-slice string:KeyError— when the comparer has no data for the selected date, xarray raises instead of returning emptyValueError: IndexVariable objects must be 1-dimensional— when daily data has an exact timestamp match,ds.sel(time='2019-01-03')returns a 0D scalar dataset, which theComparerconstructor rejectsFix (
_comparison.py):d.sel(time=time)intry/except KeyError→ empty selection on missd.expand_dims("time")when result is 0D (exact match on daily data)raw_mod_datanearest-time lookup when matched data is emptyTests (
test_comparercollection.py): replaced the# TODO: FAILScommented-out test with two correct tests covering both the overlap and no-overlap cases.